<html>
<head><meta charset="utf-8"><title>parse error for `struct i32` · wg-traits · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/index.html">wg-traits</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/parse.20error.20for.20.60struct.20i32.60.html">parse error for `struct i32`</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="214268133"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/parse%20error%20for%20%60struct%20i32%60/near/214268133" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/parse.20error.20for.20.60struct.20i32.60.html#214268133">(Oct 23 2020 at 02:31)</a>:</h4>
<p>This parse error for the program</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">struct</span> <span class="kt">i32</span> <span class="p">{}</span><span class="w"></span>
</code></pre></div>

<p>confuses me:</p>
<div class="codehilite"><pre><span></span><code>error: parse error: Unrecognized token `i32` found at 7:10
Expected one of r#&quot;([A-Za-z]|_)([A-Za-z0-9]|_)*&quot;#
</code></pre></div>


<p>Doesn't <code>i32</code> match the regex?</p>



<a name="214272533"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/parse%20error%20for%20%60struct%20i32%60/near/214272533" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/parse.20error.20for.20.60struct.20i32.60.html#214272533">(Oct 23 2020 at 04:29)</a>:</h4>
<p><code>i32</code> is handled separately as the <code>i32</code> type. So it can't be a struct name</p>



<a name="214277169"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/parse%20error%20for%20%60struct%20i32%60/near/214277169" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/parse.20error.20for.20.60struct.20i32.60.html#214277169">(Oct 23 2020 at 06:07)</a>:</h4>
<p>For what reason is <code>i32</code> in a separate syntactic class though? It seems like it could just be (an identifier that refers to) a regular type, notwithstanding the lang item status</p>



<a name="214277415"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/parse%20error%20for%20%60struct%20i32%60/near/214277415" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/parse.20error.20for.20.60struct.20i32.60.html#214277415">(Oct 23 2020 at 06:12)</a>:</h4>
<p>Actually I can't replicate this, according to <a href="https://play.rust-lang.org/?version=beta&amp;mode=debug&amp;edition=2018&amp;gist=b47332242cab659cd5792a91f7b10642">playground link</a> this isn't even an error</p>



<a name="214280888"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/parse%20error%20for%20%60struct%20i32%60/near/214280888" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/parse.20error.20for.20.60struct.20i32.60.html#214280888">(Oct 23 2020 at 07:19)</a>:</h4>
<p><span class="user-mention silent" data-user-id="271719">Mario Carneiro</span> <a href="#narrow/stream/144729-wg-traits/topic/parse.20error.20for.20.60struct.20i32.60/near/214277169">said</a>:</p>
<blockquote>
<p>For what reason is <code>i32</code> in a separate syntactic class though?</p>
</blockquote>
<p>Mainly parser simplicity. The chalk parser is mainly designed for chalk tests, so it's not as robust as the rustc parser</p>



<a name="214281027"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/parse%20error%20for%20%60struct%20i32%60/near/214281027" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lqd <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/parse.20error.20for.20.60struct.20i32.60.html#214281027">(Oct 23 2020 at 07:21)</a>:</h4>
<p>I was about to say the same as detrumi, they're talking about chalk programs not rust programs, like <a href="https://github.com/rust-lang/chalk/blob/master/tests/lowering/mod.rs#L8-L12">this</a></p>



<a name="214281136"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/parse%20error%20for%20%60struct%20i32%60/near/214281136" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/parse.20error.20for.20.60struct.20i32.60.html#214281136">(Oct 23 2020 at 07:22)</a>:</h4>
<p>Ideally the chalk parser would handle that though, so we can reliably print out chalk programs and re-parse them</p>



<a name="214281295"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/parse%20error%20for%20%60struct%20i32%60/near/214281295" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/parse.20error.20for.20.60struct.20i32.60.html#214281295">(Oct 23 2020 at 07:25)</a>:</h4>
<p>The current parser has some limitations because it's generated using lalrpop</p>



<a name="214281313"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/parse%20error%20for%20%60struct%20i32%60/near/214281313" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/parse.20error.20for.20.60struct.20i32.60.html#214281313">(Oct 23 2020 at 07:25)</a>:</h4>
<p>Oh, I missed that this is chalk</p>



<a name="214281404"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/parse%20error%20for%20%60struct%20i32%60/near/214281404" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/parse.20error.20for.20.60struct.20i32.60.html#214281404">(Oct 23 2020 at 07:26)</a>:</h4>
<p>And since chalk is mostly an internal thing I guess that means the error message doesn't need to be improved either</p>



<a name="214281409"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/parse%20error%20for%20%60struct%20i32%60/near/214281409" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/parse.20error.20for.20.60struct.20i32.60.html#214281409">(Oct 23 2020 at 07:26)</a>:</h4>
<p>Yeah, the regex in the error is from <a href="https://github.com/rust-lang/chalk/blob/420e9379dc1dbe5f022854ed452f7682cd0136a2/chalk-parse/src/parser.lalrpop#L630">here</a></p>



<a name="214281765"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/parse%20error%20for%20%60struct%20i32%60/near/214281765" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/parse.20error.20for.20.60struct.20i32.60.html#214281765">(Oct 23 2020 at 07:33)</a>:</h4>
<p>Ideally chalk would re-use the rustc parser and build on top of that, but that's probably too much effort just to have robust parsing for chalk tests</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>